package com.at.bigdata.spark.core.framework.common

import com.at.bigdata.spark.core.framework.controller.WordCountController
import com.at.bigdata.spark.core.framework.util.EnvUtil
import org.apache.spark.{SparkConf, SparkContext}

/**
 *
 * @author cdhuangchao3
 * @date 2023/5/22 6:03 PM
 */
trait TApplication {

  def start(master: String = "local[*]", app: String = "Application")(op: => Unit): Unit = {

    val sparConf = new SparkConf()
      .setMaster("local")
      .setAppName("WordCount")
    val sc = new SparkContext(sparConf)
    EnvUtil.put(sc)
    try {
      op
    } catch {
      case ex => println(ex.getMessage)
    }

    // TODO 关闭连接
    sc.stop()
    EnvUtil.clear()
  }

}
